﻿/// ****************************************************************************
/// Author:	        Robin Zhu
/// Create Date:	2015-2-27
/// Purpose: 		使用MemoryCache的timeout机制保存actionlog
/// ****************************************************************************
/// Modify By		Date			Remark
/// ****************************************************************************
/// 
using RB.Web.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;

namespace RB.Web.Mvc
{
    internal class AuthorizationLogSaver
    {
        private static MemoryCache _logCache = new MemoryCache("AuthorizationLogSaver");


        public static void Save(UserActionLog actionLog)
        {
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.SlidingExpiration = new TimeSpan(10);
            policy.RemovedCallback = new CacheEntryRemovedCallback(RemoveCallback);
            _logCache.Add(Guid.NewGuid().ToString(), actionLog, policy);
        }

        public static void RemoveCallback(CacheEntryRemovedArguments arguments)
        {
            UserActionLog actionLog = (UserActionLog)arguments.CacheItem.Value;
            VarAuthorization.LogAction(actionLog);
        }
    }
}
